package juc.Atomic;

//LongArrayTest.java的源码
import java.util.concurrent.atomic.AtomicLongArray;

public class LongArrayTest {
 
 public static void main(String[] args){

     // 新建AtomicLongArray对象
     long[] arrLong = new long[] {10, 20, 30, 40, 50};
     AtomicLongArray ala = new AtomicLongArray(arrLong);

     ala.set(0, 100);
     for (int i=0, len=ala.length(); i<len; i++) 
         System.out.printf("get(%d) : %s\n", i, ala.get(i));

     System.out.printf("%20s : %s\n", "getAndDecrement(0)", ala.getAndDecrement(0));
     System.out.printf("%20s : %s\n", "decrementAndGet(1)", ala.decrementAndGet(1));
     System.out.printf("%20s : %s\n", "getAndIncrement(2)", ala.getAndIncrement(2));
     System.out.printf("%20s : %s\n", "incrementAndGet(3)", ala.incrementAndGet(3));

     System.out.printf("%20s : %s\n", "addAndGet(100)", ala.addAndGet(0, 100));
     System.out.printf("%20s : %s\n", "getAndAdd(100)", ala.getAndAdd(1, 100));

     System.out.printf("%20s : %s\n", "compareAndSet()", ala.compareAndSet(2, 31, 1000));
     System.out.printf("%20s : %s\n", "get(2)", ala.get(2));
 }
}
/*
 * get(0) : 100
get(1) : 20
get(2) : 30
get(3) : 40
get(4) : 50
  getAndDecrement(0) : 100
  decrementAndGet(1) : 19
  getAndIncrement(2) : 30
  incrementAndGet(3) : 41
      addAndGet(100) : 199
      getAndAdd(100) : 19
     compareAndSet() : true
              get(2) : 1000
 * */
